<?php

class FormUserRegistration extends CFormModel
{
	public $email;
	public $verifyEmail;
	public $password;
	public $verifyPassword;
	public $alias;
	public $verifyCode;

	public function rules()
	{
		$rules = array();
		
		$rules[] = array('email', 'required');
		$rules[] = array('email', 'email');
		
		$rules[] = array('verifyEmail', 'required');
		$rules[] = array('verifyEmail', 'compare', 'compareAttribute' => 'email', 'message' => UserModule::t('E-Mails do not match'));
		
		$rules[] = array('password', 'required');
		$rules[] = array('password', 'length', 'min' => Yii::app()->getModule('user')->settings['password']['minLength'], 'message' => UserModule::t('Invalid password (minimal length: {min} characters)', array('{min}' => Yii::app()->getModule('user')->settings['password']['minLength'])));
		
		$rules[] = array('verifyPassword', 'required');
		$rules[] = array('verifyPassword', 'compare', 'compareAttribute' => 'password', 'message' => UserModule::t('Passwords do not match'));
		
		$rules[] = array('alias', 'required');
		$rules[] = array('alias', 'length', 'max' => Yii::app()->getModule('user')->settings['alias']['maxLength'], 'min' => Yii::app()->getModule('user')->settings['alias']['minLength'], 'message' => UserModule::t('Invalid alias (length between {min} and {max} characters)', array('{min}' => Yii::app()->getModule('user')->settings['alias']['minLength'], '{max}' => Yii::app()->getModule('user')->settings['alias']['maxLength'])));
		$rules[] = array('alias', 'match', 'pattern' => '/^[a-z0-9]{1}[a-z0-9_\-\. ]+$/iu','message' => UserModule::t('Invalid characters in alias'));
		
		if(!Yii::app()->getRequest()->isAjaxRequest)
		{
			$rules[] = array('verifyCode', 'required');
			$rules[] = array('verifyCode', 'captcha', 'allowEmpty' => !UserModule::doCaptcha('registration'));
		}
		
		return $rules;
	}

	public function attributeLabels()
	{
		return array(
			'email'          => UserModule::t('E-mail'),
			'verifyEmail'    => UserModule::t('Retype E-mail'),
			'password'       => UserModule::t('Password'),
			'verifyPassword' => UserModule::t('Retype Password'),
			'alias'          => UserModule::t('Alias'),
		);
	}

}
